<!DOCTYPE html>
<html lang=zh>
<head>
    <meta charset="utf-8">
    
    <title>8-redis-数据结构和操作 | johnny技术地</title>
    
    
        <meta name="keywords" content="redis" />
    
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta name="description" content="字符串底层数据结构sds其底层实现是简单动态字符串sds(simple dynamic string)，是可以修改的字符串。 类似于Java中的ArrayList，它采用预分配冗余空间的方式来减少内存的频繁分配。 当字符串长度小于 1M 时，扩容都是加倍现有的空间，如果超过 1M，扩容时一次只会多扩 1M 的空间。(字符串最大长度为 512M) 特点因为传统C字符串符合ASCII编码，这种编码的操">
<meta property="og:type" content="article">
<meta property="og:title" content="8-redis-数据结构和操作">
<meta property="og:url" content="https://abcd_1101.gitee.io/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/8-redis-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E6%93%8D%E4%BD%9C/index.html">
<meta property="og:site_name" content="johnny技术地">
<meta property="og:description" content="字符串底层数据结构sds其底层实现是简单动态字符串sds(simple dynamic string)，是可以修改的字符串。 类似于Java中的ArrayList，它采用预分配冗余空间的方式来减少内存的频繁分配。 当字符串长度小于 1M 时，扩容都是加倍现有的空间，如果超过 1M，扩容时一次只会多扩 1M 的空间。(字符串最大长度为 512M) 特点因为传统C字符串符合ASCII编码，这种编码的操">
<meta property="og:locale">
<meta property="og:image" content="https://abcd_1101.gitee.io/source/images/redis-string.jpg">
<meta property="article:published_time" content="2021-09-04T08:06:22.000Z">
<meta property="article:modified_time" content="2021-10-09T03:23:39.683Z">
<meta property="article:author" content="Johnny">
<meta property="article:tag" content="redis">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://abcd_1101.gitee.io/source/images/redis-string.jpg">
    

    
        <link rel="alternate" href="/atom.xml" title="johnny技术地" type="application/atom+xml" />
    

    
        <link rel="icon" href="/gitee-internal-blog/favicon.ico" />
    

    
<link rel="stylesheet" href="/gitee-internal-blog/libs/font-awesome/css/font-awesome.min.css">

    
<link rel="stylesheet" href="/gitee-internal-blog/libs/open-sans/styles.css">

    
<link rel="stylesheet" href="/gitee-internal-blog/libs/source-code-pro/styles.css">


    
<link rel="stylesheet" href="/gitee-internal-blog/css/style.css">

    
<script src="/gitee-internal-blog/libs/jquery/2.1.3/jquery.min.js"></script>

    
<script src="/gitee-internal-blog/libs/jquery/plugins/cookie/1.4.1/jquery.cookie.js"></script>

    
    
        
<link rel="stylesheet" href="/gitee-internal-blog/libs/lightgallery/css/lightgallery.min.css">

    
    
        
<link rel="stylesheet" href="/gitee-internal-blog/libs/justified-gallery/justifiedGallery.min.css">

    
    
    
    


    
        <script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
    <div id="container">
        <header id="header">
    <div id="header-main" class="header-inner">
        <div class="outer">
            <a href="/gitee-internal-blog/" id="logo">
                <i class="logo"></i>
                <span class="site-title">johnny技术地</span>
            </a>
            <nav id="main-nav">
                
                    <a class="main-nav-link" href="/gitee-internal-blog/">首页</a>
                
                    <a class="main-nav-link" href="/gitee-internal-blog/archives">归档</a>
                
                    <a class="main-nav-link" href="/gitee-internal-blog/categories">分类</a>
                
                    <a class="main-nav-link" href="/gitee-internal-blog/tags">标签</a>
                
                    <a class="main-nav-link" href="/gitee-internal-blog/about">关于</a>
                
            </nav>
            
            <div id="search-form-wrap">

    <form class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="Search" />
        <button type="submit" class="search-form-submit"></button>
    </form>
    <div class="ins-search">
    <div class="ins-search-mask"></div>
    <div class="ins-search-container">
        <div class="ins-input-wrapper">
            <input type="text" class="ins-search-input" placeholder="Type something..." />
            <span class="ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: 'Posts',
            PAGES: 'Pages',
            CATEGORIES: 'Categories',
            TAGS: 'Tags',
            UNTITLED: '(Untitled)',
        },
        ROOT_URL: '/gitee-internal-blog/',
        CONTENT_URL: '/gitee-internal-blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/gitee-internal-blog/js/insight.js"></script>


</div>
        </div>
    </div>
    <div id="main-nav-mobile" class="header-sub header-inner">
        <table class="menu outer">
            <tr>
                
                    <td><a class="main-nav-link" href="/gitee-internal-blog/">首页</a></td>
                
                    <td><a class="main-nav-link" href="/gitee-internal-blog/archives">归档</a></td>
                
                    <td><a class="main-nav-link" href="/gitee-internal-blog/categories">分类</a></td>
                
                    <td><a class="main-nav-link" href="/gitee-internal-blog/tags">标签</a></td>
                
                    <td><a class="main-nav-link" href="/gitee-internal-blog/about">关于</a></td>
                
                <td>
                    
    <div class="search-form">
        <input type="text" class="ins-search-input search-form-input" placeholder="Search" />
    </div>

                </td>
            </tr>
        </table>
    </div>
</header>

        <div class="outer">
            
            
                <aside id="sidebar">
   
        
    <div class="widget-wrap" id='categories'>
        <h3 class="widget-title">
            <span>categories</span>
            &nbsp;
            <a id='allExpand' href="#">
                <i class="fa fa-angle-double-down fa-2x"></i>
            </a>
        </h3>
        
        
        
         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            DLT
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            Ledger
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            Corda
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2023/03/09/DLT/Ledger/Corda/Corda%E4%BE%8B%E5%AD%90/">Corda例子</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            概念和框架
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2023/02/04/DLT/%E6%A6%82%E5%BF%B5%E5%92%8C%E6%A1%86%E6%9E%B6/%E5%8C%BA%E5%9D%97%E9%93%BE%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80/">区块链理论基础</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            IDE
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/05/03/IDE-eclipse-debug-f5-8/">IDE eclipse debug f5-8</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            docker_k8s
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/06/19/docker_k8s/springcloud%20vs%20k8s/"></a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/06/docker_k8s/%E5%AE%B9%E5%99%A8-docker-k8s/">容器-docker-k8s</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            git
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/05/git-reset-and-revert/">git reset and revert</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/04/14/git-pull-request-to-contribute-other-project/">Pull request to contribute other project</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/04/18/git-stash%E7%94%A8%E6%B3%95/">git stash用法</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/16/git-tag%E8%AE%B0%E5%BD%95%E7%89%88%E6%9C%AC%E5%AF%B9%E5%BA%94commit/">git tag记录版本对应commit</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            java
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/25/java%E5%9F%BA%E7%A1%801/">java基础1</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            jvm
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            性能监测
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/11/jvisualvm%E5%92%8Csprintboot%20admin%E6%80%A7%E8%83%BD%E7%9B%91%E6%B5%8B/">jvisualvm和sprintboot admin性能监测</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            linux
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            常用命令
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/11/linux%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/">linux常用命令</a></li>  </ul> 
                    </li> 
                     <li class="file"><a href="/gitee-internal-blog/2021/04/18/linux-find%E5%91%BD%E4%BB%A4/">linux-find命令</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            spring
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/05/01/spring-log%E6%97%A5%E5%BF%97%E8%AE%B0%E5%BD%95/">日志记录</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/03/spring-mvc%E5%BF%85%E5%A4%87%E9%85%8D%E7%BD%AE/">spring mvc必备配置</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/23/spring%E8%84%9A%E6%89%8B%E6%9E%B6%E5%8E%9F%E7%90%86/">spring脚手架原理</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            windows
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/17/windows-dns%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%9C%AA%E5%93%8D%E5%BA%94/">windows dns服务器未响应</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            中间件
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            mq
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/2-mq%E9%87%8D%E5%A4%8D%E9%A1%BA%E5%BA%8F%E6%B6%88%E8%B4%B9/">2-mq重复顺序消费</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/1-mq%E5%9F%BA%E7%A1%80/">1-mq基础</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/0-mq-zookeeper%E6%98%AF%E4%BB%80%E4%B9%88/">0-mq-zookeeper是什么</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/3-mq-kafka%E5%85%A5%E9%97%A8/">3-mq-kafka入门</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/4-mq%E9%97%AE%E9%A2%98%E4%B8%8D%E4%B8%A2%E5%A4%B1-%E9%87%8D%E5%A4%8D-%E6%9C%89%E5%BA%8F-%E5%A0%86%E7%A7%AF/">4-mq问题不丢失_重复_有序_堆积</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/05/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/5-mq-kafka-segement%E8%AF%BB%E5%86%99/">5-mq-kafka-segement读写</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/07/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/6-mq-kafka%E4%B8%89%E8%BF%9E%E5%87%BB/">6-mq-kafka三连击</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/12/%E4%B8%AD%E9%97%B4%E4%BB%B6/mq/7-mq-kafka%E6%98%AF%E6%8E%A8%E8%BF%98%E6%98%AF%E6%8B%89/">7-mq-kafka是推还是拉</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            必会框架
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/09/06/%E5%BF%85%E4%BC%9A%E6%A1%86%E6%9E%B6/%E6%A1%86%E6%9E%B6-%E9%AB%98%E6%80%A7%E8%83%BDNIO-Netty/">框架-高性能NIO-Netty</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            操作系统
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/09/06/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F-pageCache/">操作系统-pageCache</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/06/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F-nioFilechannel%E5%A0%86%E5%A4%96directBuffer%E4%B8%8E%E5%A0%86%E5%86%85byteBuffer/">操作系统-nioFilechannel堆外directBuffer与堆内byteBufferbyteBuffer</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/06/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E4%BC%98%E5%8C%96%E6%8F%A1%E6%89%8B%E6%8C%A5%E6%89%8B/">操作系统-计算机网络优化握手挥手</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/06/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E5%B8%B8%E9%97%AE/">操作系统-计算机网络常问</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/06/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F/%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C%E6%8A%93%E5%8C%85/">操作系统-计算机网络抓包</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory open">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder-open"></i>
                            &nbsp;
                            数据库
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            mysql
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/0-mysql%E7%BB%93%E6%9E%84%E4%B8%8E%E6%8F%92%E5%85%A5/">0-mysql结构与插入</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/1-mysql%E4%B8%80%E8%87%B4%E6%80%A7%E8%AF%BB-%E4%BA%8B%E5%8A%A1%E5%9B%9E%E6%BB%9A-mvcc/">1-mysql一致性读-事务回滚-mvcc</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/3-mysql-sql%E6%89%A7%E8%A1%8C%E8%BF%87%E7%A8%8B%E5%AE%8F%E8%A7%82%E6%B5%81%E7%A8%8B-redo-undo-bin/">3-mysql-sql执行过程宏观流程-redo-undo-bin</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/5-mysql-sql%E8%B0%83%E4%BC%98%E6%80%9D%E8%B7%AF/">5-mysql-sql调优思路</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/4-mysql-explain%E6%89%A7%E8%A1%8C%E5%85%B7%E4%BD%93%E6%B5%81%E7%A8%8B/">4-mysql-explain执行具体流程</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/6-mysql-%E7%B4%A2%E5%BC%95%E4%BD%9C%E7%94%A8%E5%92%8C%E8%AE%BE%E8%AE%A1/">6-mysql-索引作用和设计</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/8-mysql-%E6%95%B0%E6%8D%AE%E5%BA%93%E8%BF%9E%E6%8E%A5%E6%B1%A0%E8%AE%BE%E5%A4%9A%E5%A4%A7/">8-mysql-数据库连接池设多大</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/9-mysql-%E4%BB%8E%E4%B8%9A%E5%8A%A1%E5%88%B0%E6%95%B0%E6%8D%AE%E5%BA%93%E8%AE%BE%E8%AE%A1-%E8%BD%AF%E4%BB%B6%E5%B7%A5%E7%A8%8B/">9-mysql-从业务到数据库设计-软件工程</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/7-mysql-changebuffer-merge/">7-mysql-changebuffer-merge</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/2-mysql-undo-purge_bin_redo-flush%E8%84%8F%E9%A1%B5/">2-mysql-undo-purge_bin_redo-flush脏页</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/10-mysql-mysql8%E6%96%B0%E7%89%B9%E6%80%A7/">10-mysql-mysql8新特性</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/12-mysql-%E5%85%A8%E5%B1%80%E9%94%81-%E8%A1%A8%E9%94%81-%E8%A1%8C%E9%94%81/">12-mysql-全局锁-表锁-行锁</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/11-mysql-%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%92%8C%E5%AE%9E%E6%88%98/">11-mysql-主从复制和实战</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/13-mysql-%E6%9E%B6%E6%9E%84%E6%96%B9%E6%A1%88/">13-mysql-架构方案</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory open">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder-open"></i>
                            &nbsp;
                            redis
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file active"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/8-redis-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E6%93%8D%E4%BD%9C/">8-redis-数据结构和操作</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/11-redis-%E5%8F%AF%E7%94%A8%E6%80%A7-mysql%E4%B8%80%E8%87%B4%E6%80%A7%E9%97%AE%E9%A2%98/">11-redis-可用性-mysql一致性问题</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/1-redis-%E5%A5%BD-%E4%BD%BF%E7%94%A8%E5%9C%BA%E6%99%AF/">1-redis-好-使用场景</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/2-redis-%E5%BF%AB-%E5%86%85%E5%AD%98%E8%80%97%E5%B0%BD%E5%90%8E%E4%BC%9A%E6%80%8E%E6%A0%B7/">2-redis-快-内存耗尽后会怎样</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/3-redis-%E5%BF%AB-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E6%93%8D%E4%BD%9C/">3-redis-快-数据结构和操作</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/4-redis-%E5%BF%AB-%E4%B8%BA%E4%BD%95%E5%8F%98%E5%A4%9A%E7%BA%BF%E7%A8%8B/">4-redis-快-为何变多线程</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/7-redis-%E4%BC%98%E5%8C%96-%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5/"></a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/8-redis-%E4%BC%98%E5%8C%96-%E9%9B%AA%E5%B4%A9-%E7%A9%BF%E9%80%8F-%E5%87%BB%E7%A9%BF/">8-redis-优化-雪崩-穿透-击穿</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/9-redis-%E5%8F%AF%E7%94%A8%E6%80%A7-%E6%8C%81%E4%B9%85%E5%8C%96/">9-redis-可用性-持久化</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/20-redis-%E9%9D%A2%E8%AF%95%E9%A2%98/">20-redis-面试题</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/5-redis-%E5%BF%AB-%E5%A4%9A%E8%B7%AFio%E5%A4%8D%E7%94%A8/">5-redis-快-多路io复用</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/6-redis-%E4%BC%98%E5%8C%96-%E5%8F%98%E6%85%A2%E4%BA%86%E5%90%97/">6-redis-优化-变慢了吗</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/10-redis-%E5%8F%AF%E7%94%A8%E6%80%A7-%E9%9B%86%E7%BE%A4%E7%AF%87/">10-redis-可用性-集群篇</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            知识点框架
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            19-数据库
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/08/02/19-1-Oracle%E5%B8%B8%E8%80%83/">19-1-Oracle常考</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            2-jvm
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/06/25/2-1-JVM%E8%84%91%E5%9B%BE/">2-1-JVM脑图</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/25/2-2-JVM%E5%86%85%E5%AD%98%E5%8C%BA%E5%9F%9F/">2-2-JVM内存区域</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/26/2-3-jvm%E8%BF%90%E8%A1%8C%E6%97%B6%E5%86%85%E5%AD%98/">2-3-jvm运行时内存</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/26/2-4-%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6-%E7%AE%97%E6%B3%95-%E9%80%83%E9%80%B8%E5%88%86%E6%9E%90/">2-4-垃圾回收-算法-逃逸分析</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/27/2-5-java%E5%9B%9B%E7%A7%8D%E5%BC%95%E7%94%A8%E7%B1%BB%E5%9E%8B/">2-5-java四种引用类型</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/28/2-6-7-gc%E7%AE%97%E6%B3%95%E5%92%8C%E5%9E%83%E5%9C%BE%E6%94%B6%E9%9B%86%E5%99%A8/">2-6-7-gc算法和垃圾收集器</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/28/2-8-java-io-and-nio/">2-8-java io and nio</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/29/2-9-jvm%E7%B1%BB%E5%8A%A0%E8%BD%BD%E6%9C%BA%E5%88%B6/">2-9-jvm类加载机制</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            3-java集合
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/06/30/3-1-java%E6%8E%A5%E5%8F%A3%E7%BB%A7%E6%89%BF%E5%85%B3%E7%B3%BB%E4%B8%8E%E5%AE%9E%E7%8E%B0/">3-1-java接口继承关系与实现</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/30/3-2-List/">3-2-List</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/01/3-3-Set/">3-3-Set</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/01/3-4-Map%E6%98%A0%E5%B0%84/">3-4-Map映射</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            4-java多线程
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/07/02/4-1-2-%E5%A4%9A%E7%BA%BF%E7%A8%8B%E8%84%91%E5%9B%BE%E5%92%8C%E5%9B%9B%E7%A7%8D%E7%BA%BF%E7%A8%8B%E5%88%9B%E5%BB%BA%E6%96%B9%E6%B3%95/">4-1-2-多线程脑图和四种线程创建</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/02/4-3-4%E7%A7%8D%E7%BA%BF%E7%A8%8B%E6%B1%A0/">4-3-4种线程池</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/02/4-4-%E7%BA%BF%E7%A8%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F5%E7%A7%8D%E7%8A%B6%E6%80%81/">4-4-线程生命周期5种状态</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/02/4-5-%E7%BB%88%E6%AD%A2%E7%BA%BF%E7%A8%8B4%E6%96%B9%E5%BC%8F/">4-5-终止线程4方式</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/02/4-6-7-sleep%E4%B8%8Ewait-start%E4%B8%8Erun/">4-6-7-sleep与wait-start与run</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/03/4-8-java%E5%90%8E%E5%8F%B0%E7%BA%BF%E7%A8%8B/">4-8-java后台线程</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/03/4-9-java%E9%94%81/">4-9-java锁</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/05/4-10-%E7%BA%BF%E7%A8%8B%E5%9F%BA%E6%9C%AC%E6%96%B9%E6%B3%95/">4-10-线程基本方法</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/06/4-11-%E7%BA%BF%E7%A8%8B%E4%B8%8A%E4%B8%8B%E6%96%87%E5%88%87%E6%8D%A2/">4-11-线程上下文切换</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/06/4-12-%E5%90%8C%E6%AD%A5%E9%94%81%E4%B8%8E%E6%AD%BB%E9%94%81/">4-12-同步锁与死锁</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/06/4-13-%E7%BA%BF%E7%A8%8B%E6%B1%A0%E5%8E%9F%E7%90%86/">4-13-线程池原理</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/08/4-14-%E9%98%BB%E5%A1%9E%E9%98%9F%E5%88%97/">4-14-阻塞队列</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/10/4-15-cyclicBarrier-countdownlatch-semaphore/">4-15-cyclicBarrier-countdownlatch-semaphore</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/14/4-16-volatile%E5%85%B3%E9%94%AE%E5%AD%97%E4%BD%9C%E7%94%A8/">4-16-volatile关键字作用</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/14/4-17-%E4%B8%A4%E4%B8%AA%E7%BA%BF%E7%A8%8B%E5%85%B1%E4%BA%AB%E6%95%B0%E6%8D%AE/">4-17-两个线程共享数据</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/16/4-18-ThreadLocal%E4%BD%9C%E7%94%A8/">4-18-ThreadLocal作用</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/16/4-19-synchronized%E5%92%8Creentrantlock%E5%8C%BA%E5%88%AB/">4-19-synchronized和reentrantlock区别</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/17/4-20-ConcurrentHashMap/">4-20-ConcurrentHashMap</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/17/4-21-22-java%E7%BA%BF%E7%A8%8B%E8%B0%83%E5%BA%A6%E5%92%8C%E7%AE%97%E6%B3%95/">4-21-22-java线程调度和算法</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/17/4-23-cas%E6%AF%94%E8%BE%83%E5%B9%B6%E4%BA%A4%E6%8D%A2/">4-23-cas比较并交换</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/17/4-24-aqs%E6%8A%BD%E8%B1%A1%E7%9A%84%E9%98%9F%E5%88%97%E5%90%8C%E6%AD%A5%E5%99%A8/">4-24-aqs抽象的队列同步器</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            5-java基础
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/07/19/5-1-exception%E5%BC%82%E5%B8%B8%E5%88%86%E7%B1%BB%E5%8F%8A%E5%A4%84%E7%90%86/">5-1-exception异常分类及处理</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/20/5-2-java%E5%8F%8D%E5%B0%84/">5-2-java反射</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/22/5-3-java%E6%B3%A8%E8%A7%A3annotation/">5-3-java注解annotation</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/24/5-4-java%E5%86%85%E9%83%A8%E7%B1%BB/">5-4-java内部类</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/14/5-5-jdk8-lambda/">5-5-jdk8-lambda</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/14/5-6-RxJava/">5-6-RxJava</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/14/5-7-java-Observer%E6%8E%A5%E5%8F%A3%E5%92%8CObservable%E7%B1%BB/">5-7-java-Observer接口和Observable类</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            6-spring
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/05/03/6-2-springboot%E5%B8%B8%E8%80%83/">6-2-springboot常考</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/31/6-1-spring%E5%B8%B8%E8%80%83/">6-1-spring常考</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/28/6-3-springcloud%E7%94%A8%E8%BF%87%E7%9A%84/">6-3-springcloud用过的</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            面试的项目实现
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            中间件
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            es
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E4%B8%AD%E9%97%B4%E4%BB%B6/es/es/">es</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            微服务
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/08/21/%E9%9D%A2%E8%AF%95%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/%E5%BE%AE%E6%9C%8D%E5%8A%A1/hystrix/"></a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            数据库
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            mysql
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/09/04/%E9%9D%A2%E8%AF%95%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/0-mysql%E7%BB%93%E6%9E%84%E4%B8%8E%E6%8F%92%E5%85%A5/">0-mysql结构与插入</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            自动补全
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E9%9D%A2%E8%AF%95%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8/es%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8/">es自动补全</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/21/%E9%9D%A2%E8%AF%95%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8/redis%E8%87%AA%E5%8A%A8%E8%A1%A5%E5%85%A8/"></a></li>  </ul> 
                    </li> 
                     <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E9%9D%A2%E8%AF%95%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/IJP%E9%9D%A2%E8%AF%95%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/">IJP面试项目实现</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E9%9D%A2%E8%AF%95%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/Ex%E9%9D%A2%E8%AF%95%E9%A1%B9%E7%9B%AE%E5%AE%9E%E7%8E%B0/">Ex面试项目实现</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            面试题
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E9%9D%A2%E8%AF%95%E9%A2%98/SpringBoot+Tomcat+Nginx+Netty%E9%9D%A2%E8%AF%95%E9%A2%98/">SpringBoot+Tomcat+Nginx+Netty面试题</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E9%9D%A2%E8%AF%95%E9%A2%98/%E9%98%BF%E9%87%8C%E9%9D%A2%E8%AF%95%E4%BA%8C/">阿里面试题2</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/06/25/%E9%9D%A2%E8%AF%95%E9%A2%98/%E9%98%BF%E9%87%8C%E9%9D%A2%E8%AF%95%E4%B8%80/">阿里面试题1</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/16/%E9%9D%A2%E8%AF%95%E9%A2%98-java%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%9516%E9%97%AE/">面试题-java基础面试16问</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            项目经历
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            2019
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            xinge_notification
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/05/oracle_explain/">Oracle explain</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            2021
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            房贷项目
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/05/%E9%A1%B9%E7%9B%AE%E4%BB%8E0%E5%88%B01/">项目从0到1</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/04/12/email-telnet-smtp-health-check/">email telnet smtp health check</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/04/12/%E5%8E%8B%E6%B5%8B%E5%8F%82%E6%95%B0%E6%8C%87%E6%A0%87/">压测参数指标</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/04/12/checkmarx%E5%AE%89%E5%85%A8%E6%89%AB%E6%8F%8F/">checkmarx安全扫描</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/04/25/db-table-annotation/">db table annotation</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/04/25/jdbctemplate-sql-injection/">jdbctemplate sql injection</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            微信开发
                        </a>
                         <ul class="unstyled" id="tree" > 
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            安全
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/05/16/%E5%AE%89%E5%85%A8-java-ssl%E9%94%99%E8%AF%AF%E8%A7%A3%E5%86%B3%E7%A5%9E%E5%99%A8-net-debug%E5%8F%82%E6%95%B0/">安全-java ssl 错误解决神器 net debug参数</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/28/%E5%AE%89%E5%85%A8-%E5%8A%A0%E5%AF%86%E6%9C%BA/">安全-加密机</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            容器
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/07/28/%E6%9C%8D%E5%8A%A1%E5%99%A8/%E6%9C%8D%E5%8A%A1%E5%99%A8-IBM%20websphere%E7%BB%8F%E9%AA%8C%20-%20%E5%89%AF%E6%9C%AC/">服务器-IBM websphere经验</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/28/%E6%9C%8D%E5%8A%A1%E5%99%A8/%E6%9C%8D%E5%8A%A1%E5%99%A8-Tomcat%E7%BB%8F%E9%AA%8C/">服务器-Tomcat经验</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/07/28/%E6%9C%8D%E5%8A%A1%E5%99%A8/%E6%9C%8D%E5%8A%A1%E5%99%A8-IBM%20websphere%E7%BB%8F%E9%AA%8C/">服务器-IBM websphere经验</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/15/docker_k8s/%E5%AE%B9%E5%99%A8-k8s%E7%BD%91%E9%A1%B5%E5%B8%B8%E8%A7%81%E5%90%8D%E8%AF%8D/">容器-k8s网页常见名词</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/09/06/docker_k8s/%E5%AE%B9%E5%99%A8-Istio/">容器-Istio</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            小程序
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/05/16/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8FnavigateTo%E4%B8%8EredirectTo%E5%8C%BA%E5%88%AB/">小程序navigateTo与redirectTo区别</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/08/30/%E5%BE%AE%E4%BF%A1%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%9A%84%E9%85%8D%E7%BD%AE/">微信小程序的配置</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            手机抓包
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/04/10/Fiddler%E5%AF%B9%E5%AE%89%E5%8D%93%E7%A7%BB%E5%8A%A8%E7%AB%AF%E7%9A%84%E6%8A%93%E5%8C%85%E6%B5%8B%E8%AF%95/">Fiddler对安卓移动端的抓包测试</a></li>  </ul> 
                    </li> 
                    
                    <li class="directory">
                        <a href="#" data-role="directory">
                            <i class="fa fa-folder"></i>
                            &nbsp;
                            高级群发系统
                        </a>
                         <ul class="unstyled" id="tree" >  <li class="file"><a href="/gitee-internal-blog/2021/05/09/Oracle-clob%E5%AD%97%E6%AE%B5/">Oracle clob字段</a></li>  </ul> 
                    </li> 
                     <li class="file"><a href="/gitee-internal-blog/2021/04/18/%E9%A1%B9%E7%9B%AE%E6%80%A7%E8%83%BD%E5%8F%82%E6%95%B0/">项目性能参数</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/09/%E5%BE%AE%E4%BF%A1%E6%8E%A5%E5%8F%A3%E6%B3%A8%E6%84%8F%E7%82%B9%E6%B1%87%E9%9B%86/">微信接口注意点汇集</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/09/%E5%BE%AE%E4%BF%A1%E4%B8%93%E7%BA%BF%E7%9A%84%E7%BD%91%E7%BB%9C%E5%B1%82%E7%90%86%E8%A7%A3/">专线的网络层理解</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/15/%E5%BE%AE%E4%BF%A1Sprint-plan/">Sprint plan</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/15/%E5%BE%AE%E4%BF%A1%E4%B8%8E%E9%93%B6%E8%81%94%E7%9A%84sso%E5%8D%95%E7%82%B9%E7%99%BB%E5%BD%95/">微信与银联的sso单点登录</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/22/G3%E8%87%AA%E5%8A%A8%E5%8C%96/">G3自动化</a></li>  <li class="file"><a href="/gitee-internal-blog/2021/05/29/%E5%BE%AE%E4%BF%A1%E9%A1%B9%E7%9B%AE%E5%BE%80ikp%E6%90%AC/">微信项目往ikp搬</a></li>  </ul> 
                    </li> 
                     </ul> 
                    </li> 
                     </ul> 
    </div>
    <script>
        $(document).ready(function() {
            var iconFolderOpenClass  = 'fa-folder-open';
            var iconFolderCloseClass = 'fa-folder';
            var iconAllExpandClass = 'fa-angle-double-down';
            var iconAllPackClass = 'fa-angle-double-up';
            // Handle directory-tree expansion:
            // 左键单独展开目录
            $(document).on('click', '#categories a[data-role="directory"]', function (event) {
                event.preventDefault();

                var icon = $(this).children('.fa');
                var expanded = icon.hasClass(iconFolderOpenClass);
                var subtree = $(this).siblings('ul');
                icon.removeClass(iconFolderOpenClass).removeClass(iconFolderCloseClass);
                if (expanded) {
                    if (typeof subtree != 'undefined') {
                        subtree.slideUp({ duration: 100 });
                    }
                    icon.addClass(iconFolderCloseClass);
                } else {
                    if (typeof subtree != 'undefined') {
                        subtree.slideDown({ duration: 100 });
                    }
                    icon.addClass(iconFolderOpenClass);
                }
            });
            // 右键展开下属所有目录
            $('#categories a[data-role="directory"]').bind("contextmenu", function(event){
                event.preventDefault();
                
                var icon = $(this).children('.fa');
                var expanded = icon.hasClass(iconFolderOpenClass);
                var listNode = $(this).siblings('ul');
                var subtrees = $.merge(listNode.find('li ul'), listNode);
                var icons = $.merge(listNode.find('.fa'), icon);
                icons.removeClass(iconFolderOpenClass).removeClass(iconFolderCloseClass);
                if(expanded) {
                    subtrees.slideUp({ duration: 100 });
                    icons.addClass(iconFolderCloseClass);
                } else {
                    subtrees.slideDown({ duration: 100 });
                    icons.addClass(iconFolderOpenClass);
                }
            })
            // 展开关闭所有目录按钮
            $(document).on('click', '#allExpand', function (event) {
                event.preventDefault();
                
                var icon = $(this).children('.fa');
                var expanded = icon.hasClass(iconAllExpandClass);
                icon.removeClass(iconAllExpandClass).removeClass(iconAllPackClass);
                if(expanded) {
                    $('#sidebar .fa.fa-folder').removeClass('fa-folder').addClass('fa-folder-open')
                    $('#categories li ul').slideDown({ duration: 100 });
                    icon.addClass(iconAllPackClass);
                } else {
                    $('#sidebar .fa.fa-folder-open').removeClass('fa-folder-open').addClass('fa-folder')
                    $('#categories li ul').slideUp({ duration: 100 });
                    icon.addClass(iconAllExpandClass);
                }
            });  
        });
    </script>

    
    <div id="toTop" class="fa fa-angle-up"></div>
</aside>
            
            <section id="main"><article id="post-数据库/redis/8-redis-数据结构和操作" class="article article-type-post" itemscope itemprop="blogPost">
    <div class="article-inner">
        
        
            <header class="article-header">
                
                    <div class="article-meta">
                        
    <div class="article-category">
    	<i class="fa fa-folder"></i>
        <a class="article-category-link" href="/gitee-internal-blog/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a><i class="fa fa-angle-right"></i><a class="article-category-link" href="/gitee-internal-blog/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/">redis</a>
    </div>

                        
    <div class="article-tag">
        <i class="fa fa-tag"></i>
        <a class="tag-link-link" href="/gitee-internal-blog/tags/redis/" rel="tag">redis</a>
    </div>

                        
    <div class="article-date">
        <i class="fa fa-calendar"></i>
        <a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/8-redis-%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%92%8C%E6%93%8D%E4%BD%9C/">
            <time datetime="2021-09-04T08:06:22.000Z" itemprop="datePublished">2021-09-04</time>
        </a>
    </div>


                        
                            <i class="fa fa-bar-chart"></i>
                            <span id="busuanzi_container_site_pv"><span id="busuanzi_value_page_pv"></span></span>    
                        
                        
                            <div class="article-meta-button">
                                <a target="_blank" rel="noopener" href='https://github.com/zthxxx/Wiki-site/raw/writing/source/_posts/数据库/redis/8-redis-数据结构和操作.md'> Source </a>
                            </div>
                            <div class="article-meta-button">
                                <a target="_blank" rel="noopener" href='https://github.com/zthxxx/Wiki-site/edit/writing/source/_posts/数据库/redis/8-redis-数据结构和操作.md'> Edit </a>
                            </div>
                            <div class="article-meta-button">
                                <a target="_blank" rel="noopener" href='https://github.com/zthxxx/Wiki-site/commits/writing/source/_posts/数据库/redis/8-redis-数据结构和操作.md'> History </a>
                            </div>
                        
                    </div>
                
                
    
        <h1 class="article-title" itemprop="name">
            8-redis-数据结构和操作
        </h1>
    

            </header>
        
        
        <div class="article-entry" itemprop="articleBody">
        
        
            
                <div id="toc" class="toc-article">
                <strong class="toc-title">Catalogue</strong>
                    <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">1.</span> <span class="toc-text">字符串</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BA%95%E5%B1%82%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84sds"><span class="toc-number">1.1.</span> <span class="toc-text">底层数据结构sds</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%89%B9%E7%82%B9"><span class="toc-number">1.1.1.</span> <span class="toc-text">特点</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AD%98%E5%82%A8%E6%A0%BC%E5%BC%8Femb%E5%92%8Craw"><span class="toc-number">1.2.</span> <span class="toc-text">存储格式emb和raw</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%A9%E5%AE%B9"><span class="toc-number">1.3.</span> <span class="toc-text">扩容</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BC%A9%E5%AE%B9"><span class="toc-number">1.4.</span> <span class="toc-text">缩容</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#hash"><span class="toc-number">2.</span> <span class="toc-text">hash</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%89%A9%E7%BC%A9%E5%AE%B9"><span class="toc-number">2.1.</span> <span class="toc-text">扩缩容</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#list"><span class="toc-number">3.</span> <span class="toc-text">list</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#ziplist"><span class="toc-number">3.1.</span> <span class="toc-text">ziplist</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#quicklist"><span class="toc-number">3.2.</span> <span class="toc-text">quicklist</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#set"><span class="toc-number">4.</span> <span class="toc-text">set</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#sorted-set"><span class="toc-number">5.</span> <span class="toc-text">sorted set</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%AB%98%E9%98%B6"><span class="toc-number">6.</span> <span class="toc-text">高阶</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#redis-steam"><span class="toc-number">6.1.</span> <span class="toc-text">redis steam</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#geohash"><span class="toc-number">6.2.</span> <span class="toc-text">geohash</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%93%8D%E4%BD%9C"><span class="toc-number">7.</span> <span class="toc-text">操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%81%87%E5%A6%82Redis%E9%87%8C%E9%9D%A2%E6%9C%891%E4%BA%BF%E4%B8%AAkey%EF%BC%8C%E5%85%B6%E4%B8%AD%E6%9C%8910w%E4%B8%AAkey%E6%98%AF%E4%BB%A5%E6%9F%90%E4%B8%AA%E5%9B%BA%E5%AE%9A%E7%9A%84%E5%B7%B2%E7%9F%A5%E7%9A%84%E5%89%8D%E7%BC%80%E5%BC%80%E5%A4%B4%E7%9A%84%EF%BC%8C%E5%A6%82%E4%BD%95%E5%B0%86%E5%AE%83%E4%BB%AC%E5%85%A8%E9%83%A8%E6%89%BE%E5%87%BA%E6%9D%A5%EF%BC%9F"><span class="toc-number">7.1.</span> <span class="toc-text">假如Redis里面有1亿个key，其中有10w个key是以某个固定的已知的前缀开头的，如何将它们全部找出来？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%B9%E6%96%B9%E6%8E%A5%E7%9D%80%E8%BF%BD%E9%97%AE%EF%BC%9A%E5%A6%82%E6%9E%9C%E8%BF%99%E4%B8%AAredis%E6%AD%A3%E5%9C%A8%E7%BB%99%E7%BA%BF%E4%B8%8A%E7%9A%84%E4%B8%9A%E5%8A%A1%E6%8F%90%E4%BE%9B%E6%9C%8D%E5%8A%A1%EF%BC%8C%E9%82%A3%E4%BD%BF%E7%94%A8keys%E6%8C%87%E4%BB%A4%E4%BC%9A%E6%9C%89%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98%EF%BC%9F"><span class="toc-number">7.2.</span> <span class="toc-text">对方接着追问：如果这个redis正在给线上的业务提供服务，那使用keys指令会有什么问题？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BD%BF%E7%94%A8%E8%BF%87Redis%E5%81%9A%E5%BC%82%E6%AD%A5%E9%98%9F%E5%88%97%E4%B9%88%EF%BC%8C%E4%BD%A0%E6%98%AF%E6%80%8E%E4%B9%88%E7%94%A8%E7%9A%84%EF%BC%9F"><span class="toc-number">7.3.</span> <span class="toc-text">使用过Redis做异步队列么，你是怎么用的？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A6%82%E6%9E%9C%E5%AF%B9%E6%96%B9%E8%BF%BD%E9%97%AE%E5%8F%AF%E4%B8%8D%E5%8F%AF%E4%BB%A5%E4%B8%8D%E7%94%A8sleep%E5%91%A2%EF%BC%9F"><span class="toc-number">7.4.</span> <span class="toc-text">如果对方追问可不可以不用sleep呢？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A6%82%E6%9E%9C%E5%AF%B9%E6%96%B9%E6%8E%A5%E7%9D%80%E8%BF%BD%E9%97%AE%E8%83%BD%E4%B8%8D%E8%83%BD%E7%94%9F%E4%BA%A7%E4%B8%80%E6%AC%A1%E6%B6%88%E8%B4%B9%E5%A4%9A%E6%AC%A1%E5%91%A2%EF%BC%9F"><span class="toc-number">7.5.</span> <span class="toc-text">如果对方接着追问能不能生产一次消费多次呢？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A6%82%E6%9E%9C%E5%AF%B9%E6%96%B9%E7%BB%A7%E7%BB%AD%E8%BF%BD%E9%97%AE-pub-su-b%E6%9C%89%E4%BB%80%E4%B9%88%E7%BC%BA%E7%82%B9%EF%BC%9F"><span class="toc-number">7.6.</span> <span class="toc-text">如果对方继续追问 pub&#x2F;su b有什么缺点？</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#redis%E5%BB%B6%E6%97%B6%E9%98%9F%E5%88%97"><span class="toc-number">7.7.</span> <span class="toc-text">redis延时队列</span></a></li></ol></li></ol>
                </div>
            
        
        
            <h2 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h2><h3 id="底层数据结构sds"><a href="#底层数据结构sds" class="headerlink" title="底层数据结构sds"></a>底层数据结构sds</h3><p>其底层实现是简单动态字符串<strong>sds</strong>(simple dynamic string)，是可以修改的字符串。</p>
<p>类似于Java中的ArrayList，它采用预分配冗余空间的方式来减少内存的频繁分配。</p>
<p><strong>当字符串长度小于 1M 时，扩容都是加倍现有的空间，如果超过 1M，扩容时一次只会多扩 1M 的空间</strong>。(字符串最大长度为 <strong>512M</strong>)</p>
<h4 id="特点"><a href="#特点" class="headerlink" title="特点"></a>特点</h4><p>因为传统C字符串符合ASCII编码，这种编码的操作的特点就是：遇零则止 。即，当读一个字符串时，只要遇到’\0’结尾，就认为到达末尾，就忽略’\0’结尾以后的所有字符。因此，如果传统字符串保存图片，视频等二进制文件，操作文件时就被截断了。</p>
<p>SDS表头的buf被定义为字节数组，因为判断是否到达字符串结尾的依据则是表头的len成员，这意味着它可以存放任何二进制的数据和文本数据，包括’\0’</p>
<p>SDS 和传统的 C 字符串获得的做法不同，传统的C字符串遍历字符串的长度，遇零则止，复杂度为O(n)。而SDS表头的len成员就保存着字符串长度，所以获得字符串长度的操作复杂度为O(1)。</p>
<p><strong>总结下sds的特点是：可动态扩展内存、二进制安全、快速遍历字符串 和与传统的C语言字符串类型兼容。</strong></p>
<h3 id="存储格式emb和raw"><a href="#存储格式emb和raw" class="headerlink" title="存储格式emb和raw"></a>存储格式emb和raw</h3><p>一个字符的差别，存储形式 encoding 就发生了变化。一个是 embstr，一个是 row。</p>
<p>在了解存储格式的区别之前，首先了解下RedisObject结构体。</p>
<p>所有的 Redis 对象都有一个 Redis 对象头结构体</p>
<p>struct RedisObject {<br>    int4 type; // 4bits  类型<br>    int4 encoding; // 4bits 存储格式<br>    int24 lru; // 24bits 记录LRU信息<br>    int32 refcount; // 4bytes<br>    void *ptr; // 8bytes，64-bit system<br>} robj;<br>不同的对象具有不同的类型 type(4bit)，同一个类型的 type 会有不同的存储形式 encoding(4bit)。</p>
<p>为了记录对象的 LRU 信息，使用了 24 个 bit 的 lru 来记录 LRU 信息。</p>
<p>每个对象都有个引用计数 refcount，当引用计数为零时，对象就会被销毁，内存被回收。ptr 指针将指向对象内容 (body) 的具体存储位置。</p>
<p>一个 RedisObject 对象头共需要占据 16 字节的存储空间。</p>
<p>再看一下RedisObject的10种存储格式——encoding</p>
<p>//这两个宏定义申明是在server.h文件中<br>#define OBJ_ENCODING_RAW 0     /* Raw representation <em>/<br>#define OBJ_ENCODING_INT 1     /</em> Encoded as integer <em>/<br>#define OBJ_ENCODING_HT 2      /</em> Encoded as hash table <em>/<br>#define OBJ_ENCODING_ZIPMAP 3  /</em> Encoded as zipmap <em>/<br>#define OBJ_ENCODING_LINKEDLIST 4 /</em> No longer used: old list encoding. <em>/<br>#define OBJ_ENCODING_ZIPLIST 5 /</em> Encoded as ziplist <em>/<br>#define OBJ_ENCODING_INTSET 6  /</em> Encoded as intset <em>/<br>#define OBJ_ENCODING_SKIPLIST 7  /</em> Encoded as skiplist <em>/<br>#define OBJ_ENCODING_EMBSTR 8  /</em> Embedded sds string encoding <em>/<br>#define OBJ_ENCODING_QUICKLIST 9 /</em> Encoded as linked list of ziplists */</p>
<p>而Redis 的字符串共有两种存储方式，在长度特别短时，使用 emb 形式存储 (embedded)，当长度超过 44 时，使用 raw 形式存储。</p>
<p><img src="/source/images/redis-string.jpg" alt="image-20211007192124892"></p>
<p>embstr 存储形式是这样一种存储形式，它将 RedisObject 对象头和 SDS 对象连续存在一起，使用 malloc 方法一次分配。而 raw 存储形式不一样，它需要两次 malloc，两个对象头在内存地址上一般是不连续的。</p>
<p>在字符串比较小时，SDS 对象头的大小是capacity+3——SDS结构体的内存大小至少是 3。意味着分配一个字符串的最小空间占用为 19 字节 (16+3)。</p>
<p>如果总体超出了 64 字节，Redis 认为它是一个大字符串，不再使用 emdstr 形式存储，而该用 raw 形式。而64-19-结尾的\0，所以empstr只能容纳44字节。</p>
<h3 id="扩容"><a href="#扩容" class="headerlink" title="扩容"></a>扩容</h3><p>扩容策略是字符串在长度小于 SDS_MAX_PREALLOC 之前，扩容空间采用加倍策略，也就是保留 100% 的冗余空间。</p>
<h3 id="缩容"><a href="#缩容" class="headerlink" title="缩容"></a>缩容</h3><p>惰性空间释放用于优化SDS的字符串缩短操作。</p>
<ul>
<li>当要缩短SDS保存的字符串时，程序并不立即使用内存充分配来回收缩短后多出来的字节，而是使用表头的<strong>free</strong>成员将这些字节记录起来，并等待将来使用。</li>
</ul>
<h2 id="hash"><a href="#hash" class="headerlink" title="hash"></a>hash</h2><p><strong>Redis</strong> 中的字典相当于 Java 中的 <strong>HashMap</strong>，内部实现也差不多类似，都是通过 <strong>“数组 + 链表”</strong> 的 <strong>链地址法</strong> 来解决部分 哈希冲突，同时这样的结构也吸收了两种不同数据结构的优点。</p>
<p>字典结构内部包含 <strong>两个 hashtable</strong>，通常情况下只有一个 <code>hashtable</code> 有值，但是在字典扩容缩容时，需要分配新的 <code>hashtable</code>，然后进行 <strong>渐进式搬迁</strong> *(rehash)*，这时候两个 <code>hashtable</code> 分别存储旧的和新的 <code>hashtable</code>，待搬迁结束后，旧的将被删除，新的 <code>hashtable</code> 取而代之。</p>
<h3 id="扩缩容"><a href="#扩缩容" class="headerlink" title="扩缩容"></a>扩缩容</h3><p>当 hash 表中 <strong>元素的个数等于第一维数组的长度时</strong>，就会开始扩容，扩容的新数组是 <strong>原数组大小的 2 倍</strong>。不过如果 Redis 正在做 <code>bgsave(持久化命令)</code>，为了减少内存也得过多分离，Redis 尽量不去扩容，但是如果 hash 表非常满了，<strong>达到了第一维数组长度的 5 倍了</strong>，这个时候就会 <strong>强制扩容</strong>。</p>
<p>当 hash 表因为元素逐渐被删除变得越来越稀疏时，Redis 会对 hash 表进行缩容来减少 hash 表的第一维数组空间占用。所用的条件是 **元素个数低于数组长度的 10%**，缩容不会考虑 Redis 是否在做 <code>bgsave</code>。</p>
<h2 id="list"><a href="#list" class="headerlink" title="list"></a>list</h2><p>有序列表</p>
<p>功能：</p>
<ol>
<li>类似粉丝列表、文章的评论列表之类的东西。通过 <strong>lrange</strong> 命令，读取某个闭区间内的元素，可以基于 <strong>List</strong> 实现分页查询，这个是很棒的一个功能，基于 <strong>Redis</strong> 实现简单的高性能分页，可以做类似微博那种下拉不断分页的东西，性能高。</li>
<li>消息队列。数据的生产者可以通过<strong>Lpush</strong>命令从左边插入数据，多个数据消费者，可以使用<strong>BRpop</strong>命令阻塞的“抢”列表尾部的数据。</li>
</ol>
<h3 id="ziplist"><a href="#ziplist" class="headerlink" title="ziplist"></a>ziplist</h3><p><strong>zset</strong> 和 <strong>hash</strong> 容器对象会在元素个数较少的时候，采用压缩列表（ziplist）进行存储。压缩列表是 <strong>一块连续的内存空间</strong>，元素之间紧挨着存储，没有任何冗余空隙。</p>
<blockquote>
<p>“</p>
<p>因为之前自己也没有学习过，所以找了一篇比较好比较容易理解的文章：</p>
<ul>
<li>图解Redis之数据结构篇——压缩列表 - <a target="_blank" rel="noopener" href="https://mp.weixin.qq.com/s?__biz=MzU3OTk1MjMyMA==&mid=2247483700&idx=1&sn=8613dcc63a6419af2b941a64c2c58534&scene=21#wechat_redirect">https://mp.weixin.qq.com/s/nba0FUEAVRs0vi24KUoyQg</a></li>
<li>这一篇稍微底层稍微硬核一点：<a target="_blank" rel="noopener" href="http://www.web-lovers.com/redis-source-ziplist.html">http://www.web-lovers.com/redis-source-ziplist.html</a></li>
</ul>
</blockquote>
<h3 id="quicklist"><a href="#quicklist" class="headerlink" title="quicklist"></a>quicklist</h3><p>Redis 早期版本存储 list 列表数据结构使用的是压缩列表 ziplist 和普通的双向链表 linkedlist，也就是说当元素少时使用 ziplist，当元素多时用 linkedlist。但考虑到链表的附加空间相对较高，<code>prev</code> 和 <code>next</code> 指针就要占去 <code>16</code> 个字节（64 位操作系统占用 <code>8</code> 个字节），另外每个节点的内存都是单独分配，会家具内存的碎片化，影响内存管理效率。</p>
<p>后来 <strong>Redis 新版本（3.2）</strong>对列表数据结构进行了改造，使用 <code>quicklist</code> 代替了 <code>ziplist</code> 和 <code>linkedlist</code>。</p>
<blockquote>
<p>“</p>
<p>同上..建议阅读一下以下的文章：</p>
<ul>
<li>Redis列表list 底层原理 - <a target="_blank" rel="noopener" href="https://zhuanlan.zhihu.com/p/102422311">https://zhuanlan.zhihu.com/p/102422311</a></li>
</ul>
</blockquote>
<h2 id="set"><a href="#set" class="headerlink" title="set"></a>set</h2><p><strong>Set</strong> 是无序集合，会自动去重的那种。</p>
<p>可以基于 <strong>Set</strong> 玩儿交集、并集、差集的操作，比如交集吧，我们可以把两个人的好友列表整一个交集，看看俩人的共同好友是谁？对吧。</p>
<h2 id="sorted-set"><a href="#sorted-set" class="headerlink" title="sorted set"></a>sorted set</h2><p><strong>Sorted set</strong> 是排序的 <strong>Set</strong>，去重但可以排序，写进去的时候给一个分数，自动根据分数排序。</p>
<ul>
<li>排行榜：有序集合经典使用场景。例如视频网站需要对用户上传的视频做排行榜，榜单维护可能是多方面：按照时间、按照播放量、按照获得的赞数等。</li>
<li>用<strong>Sorted Sets</strong>来做带权重的队列，比如普通消息的score为1，重要消息的score为2，然后工作线程可以选择按score的倒序来获取工作任务。让重要的任务优先执行。</li>
</ul>
<h2 id="高阶"><a href="#高阶" class="headerlink" title="高阶"></a>高阶</h2><h3 id="redis-steam"><a href="#redis-steam" class="headerlink" title="redis steam"></a>redis steam</h3><p><strong>Redis Stream</strong> 从概念上来说，就像是一个 <strong>仅追加内容</strong> 的 <strong>消息链表</strong>，把所有加入的消息都一个一个串起来，每个消息都有一个唯一的 ID 和内容，这很简单，让它复杂的是从 Kafka 借鉴的另一种概念：<strong>消费者组(Consumer Group)</strong> *(思路一致，实现不同)*：</p>
<p>Redis 基于内存存储，这意味着它会比基于磁盘的 Kafka 快上一些，也意味着使用 Redis 我们 <strong>不能长时间存储大量数据</strong>。不过如果您想以 <strong>最小延迟</strong> 实时处理消息的话，您可以考虑 Redis，但是如果 <strong>消息很大并且应该重用数据</strong> 的话，则应该首先考虑使用 Kafka。</p>
<h3 id="geohash"><a href="#geohash" class="headerlink" title="geohash"></a>geohash</h3><p><a target="_blank" rel="noopener" href="http://mp.weixin.qq.com/s?__biz=MzUyMTg0NDA2Ng==&mid=2247484027&idx=1&sn=6237212c01a009be9a5ca88e0e50a46d&chksm=f9d5a676cea22f603e06d1e61d6293985c8ddb063621b1cdf2696da2eaeb1681e307ef2a3f20&scene=21#wechat_redirect">Redis(6)——GeoHash查找附近的人</a></p>
<h2 id="操作"><a href="#操作" class="headerlink" title="操作"></a>操作</h2><h3 id="假如Redis里面有1亿个key，其中有10w个key是以某个固定的已知的前缀开头的，如何将它们全部找出来？"><a href="#假如Redis里面有1亿个key，其中有10w个key是以某个固定的已知的前缀开头的，如何将它们全部找出来？" class="headerlink" title="假如Redis里面有1亿个key，其中有10w个key是以某个固定的已知的前缀开头的，如何将它们全部找出来？"></a>假如Redis里面有1亿个key，其中有10w个key是以某个固定的已知的前缀开头的，如何将它们全部找出来？</h3><p>使用<strong>keys</strong>指令可以扫出指定模式的key列表。</p>
<h3 id="对方接着追问：如果这个redis正在给线上的业务提供服务，那使用keys指令会有什么问题？"><a href="#对方接着追问：如果这个redis正在给线上的业务提供服务，那使用keys指令会有什么问题？" class="headerlink" title="对方接着追问：如果这个redis正在给线上的业务提供服务，那使用keys指令会有什么问题？"></a>对方接着追问：如果这个redis正在给线上的业务提供服务，那使用keys指令会有什么问题？</h3><p>这个时候你要回答Redis关键的一个特性：Redis的单线程的。keys指令会导致线程阻塞一段时间，线上服务会停顿，直到指令执行完毕，服务才能恢复。这个时候可以使用<strong>scan</strong>指令，<strong>scan</strong>指令可以无阻塞的提取出指定模式的key列表，但是会有一定的重复概率，在客户端做一次去重就可以了，但是整体所花费的时间会比直接用keys指令长。</p>
<h3 id="使用过Redis做异步队列么，你是怎么用的？"><a href="#使用过Redis做异步队列么，你是怎么用的？" class="headerlink" title="使用过Redis做异步队列么，你是怎么用的？"></a>使用过Redis做异步队列么，你是怎么用的？</h3><p>一般使用list结构作为队列，<strong>rpush</strong>生产消息，<strong>lpop</strong>消费消息。当lpop没有消息的时候，要适当sleep一会再重试。</p>
<h3 id="如果对方追问可不可以不用sleep呢？"><a href="#如果对方追问可不可以不用sleep呢？" class="headerlink" title="如果对方追问可不可以不用sleep呢？"></a>如果对方追问可不可以不用sleep呢？</h3><p>list还有个指令叫<strong>blpop</strong>，在没有消息的时候，它会阻塞住直到消息到来。</p>
<h3 id="如果对方接着追问能不能生产一次消费多次呢？"><a href="#如果对方接着追问能不能生产一次消费多次呢？" class="headerlink" title="如果对方接着追问能不能生产一次消费多次呢？"></a>如果对方接着追问能不能生产一次消费多次呢？</h3><p>使用pub/sub主题订阅者模式，可以实现 1:N 的消息队列。</p>
<h3 id="如果对方继续追问-pub-su-b有什么缺点？"><a href="#如果对方继续追问-pub-su-b有什么缺点？" class="headerlink" title="如果对方继续追问 pub/su b有什么缺点？"></a>如果对方继续追问 pub/su b有什么缺点？</h3><p>在消费者下线的情况下，生产的消息会丢失，得使用专业的消息队列如<strong>RocketMQ</strong>等。</p>
<h3 id="redis延时队列"><a href="#redis延时队列" class="headerlink" title="redis延时队列"></a>redis延时队列</h3><p>使用sortedset，拿时间戳作为score，消息内容作为key调用zadd来生产消息，消费者用<strong>zrangebyscore</strong>指令获取N秒之前的数据轮询进行处理。处理完删除。</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ZRANGEBYSCORE zset (1 5</span><br></pre></td></tr></table></figure>

<p>返回所有符合条件 1 &lt; score &lt;= 5 的成员，而</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ZRANGEBYSCORE zset (5 (10</span><br></pre></td></tr></table></figure>

<p>则返回所有符合条件 5 &lt; score &lt; 10 的成员。</p>

            </div>
        
        <footer class="article-footer">
        </footer>
    </div>
</article>


    
<nav id="article-nav">
    
        <a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/mysql/11-mysql-%E4%B8%BB%E4%BB%8E%E5%A4%8D%E5%88%B6%E5%92%8C%E5%AE%9E%E6%88%98/" id="article-nav-newer" class="article-nav-link-wrap">
            <strong class="article-nav-caption">Newer</strong>
            <div class="article-nav-title">
                
                    11-mysql-主从复制和实战
                
            </div>
        </a>
    
    
        <a href="/gitee-internal-blog/2021/09/04/%E6%95%B0%E6%8D%AE%E5%BA%93/redis/11-redis-%E5%8F%AF%E7%94%A8%E6%80%A7-mysql%E4%B8%80%E8%87%B4%E6%80%A7%E9%97%AE%E9%A2%98/" id="article-nav-older" class="article-nav-link-wrap">
            <strong class="article-nav-caption">Older</strong>
            <div class="article-nav-title">11-redis-可用性-mysql一致性问题</div>
        </a>
    
</nav>





    
    




<!-- baidu url auto push script -->
<script type="text/javascript">
    !function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=window.location.href,o=document.referrer;if(!e.test(r)){var n="//api.share.baidu.com/s.gif";o?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var t=new Image;t.src=n}}(window);
</script>     
</section>
        </div>
        <footer id="footer">
    <div class="outer">
        <div id="footer-info" class="inner">
            Johnny &copy; 2023 
            <a rel="license noopener" target="_blank" href="http://creativecommons.org/licenses/by-nc-nd/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-nc-nd/4.0/80x15.png" /></a>
            <br> Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>. Theme - <a target="_blank" rel="noopener" href="https://github.com/zthxxx/hexo-theme-Wikitten">wikitten</a>
            
                <br>
                <span id="busuanzi_container_site_pv"><i class="fa fa-eye"></i> <span id="busuanzi_value_site_pv"></span></span>
                &nbsp;|&nbsp;
                <span id="busuanzi_container_site_pv"><i class="fa fa-user"></i> <span id="busuanzi_value_site_uv"></span></span>
            
        </div>
    </div>
</footer>

        

    
        
<script src="/gitee-internal-blog/libs/lightgallery/js/lightgallery.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-thumbnail.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-pager.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-autoplay.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-fullscreen.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-zoom.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-hash.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-share.min.js"></script>

        
<script src="/gitee-internal-blog/libs/lightgallery/js/lg-video.min.js"></script>

    
    
        
<script src="/gitee-internal-blog/libs/justified-gallery/jquery.justifiedGallery.min.js"></script>

    
    
        <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        tex2jax: {
            inlineMath: [ ["$","$"], ["\\(","\\)"] ],
            skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code'],
            processEscapes: true,
            TeX: {
                equationNumbers: {
                  autoNumber: 'AMS'
                }
            }
        }
    });
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax();
        for (var i = 0; i < all.length; ++i)
            all[i].SourceElement().parentNode.className += ' has-jax';
    });
</script>
<script async src="//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
    



<!-- Custom Scripts -->

<script src="/gitee-internal-blog/js/main.js"></script>


    </div>
</body>
</html>